package mq;


import com.frxs.framework.util.common.StringUtil;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * esjob黑白名单配置,只支持jvm启动参数的方式配置，避免误配置在properties或apollo中
* @author zhangweilin
* @date 2022/9/2 11:48
* @Description:
*/
@Component
@Data
public class MqConsumerWhitelistProperties {


	/**
	 * 是否禁用所有，默认为不禁用
	 * @return
	 */
	public boolean isDisableAll() {
		try {
			String value = System.getProperty("mq.consumer.disable-all");
			if (null == value || value.trim().length() == 0) {
				return false;
			}
			return new Boolean(value);
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 自定义分组tag后缀
	 * @return
	 */
	public String getMqConsumerGroupTag() {
		try {
			String mqConsumerGroupTag = System.getProperty("mq.consumer.group.tag");
			if (StringUtil.isBlank(mqConsumerGroupTag)) {
				return "";
			}else{
				return "_" + mqConsumerGroupTag;
			}
		} catch (Exception e) {
			return "";
		}
	}

	/**
	 * 启用部分mq
	 * @return
	 */
	public List<String> getIncludePathPatterns() {
		try {
			String value = System.getProperty("mq.consumer.include-path-patterns");
			if (null == value || value.trim().length() == 0) {
				return new ArrayList<>();
			}
			String[] strArr = value.split(",");
			List<String> includePathPatternList = Arrays.stream(strArr).collect(Collectors.toList());
			return includePathPatternList;
		} catch (Exception e) {
			return new ArrayList<>();
		}
	}

}
